#ifndef __MOTOR_H
#define __MOTOR_H

#include "tim.h"

#define MOTOR_REVERSE 1
#define MOTOR_NOT_REVERSE 0

typedef struct Motor_t {
	TIM_HandleTypeDef *timer_pwm1;
	TIM_HandleTypeDef *timer_pwm2;
	uint32_t channel_pwm1;
	uint32_t channel_pwm2;
	GPIO_TypeDef *dir_gpio1;
	GPIO_TypeDef *dir_gpio2;
	uint32_t dir_pin1;
	uint32_t dir_pin2;
	uint8_t reverse;
	uint8_t use_single_pwm;
	float dead_speed;	//死区速度
} Motor_t;

void MotorInit_DoublePWM(Motor_t* motor, TIM_HandleTypeDef* t1, uint32_t c1, TIM_HandleTypeDef* t2, uint32_t c2);
void MotorInit_SinglePWM(Motor_t* motor, TIM_HandleTypeDef* t1, uint32_t c1, 
												 GPIO_TypeDef *dir_gpio1, uint32_t dir_pin1, GPIO_TypeDef *dir_gpio2, uint32_t dir_pin2);
void MotorSetSpeed(Motor_t* motor, float speed);
void MotorSetReverse(Motor_t* motor, uint8_t reverse);
void MotorSetDeadSpeed(Motor_t* motor, float dead_speed);

#endif